package com.atguigu.schedule;

import com.atguigu.schedule.mapper.SecurityQuestionMapper;
import com.atguigu.schedule.pojo.SecurityQuestion;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.Arrays;
import java.util.List;

/**
 * Spring Boot 主启动类
 * 
 * @author atguigu
 * @since 2024
 */
@SpringBootApplication
@EnableScheduling
public class SmartCarApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(SmartCarApplication.class, args);
    }

    /**
     * 初始化默认安全问题数据
     */
    @Bean
    public static CommandLineRunner initSecurityQuestions(SecurityQuestionMapper securityQuestionMapper) {
        return args -> {
            // 检查是否已有安全问题数据
            if (securityQuestionMapper.selectAll().isEmpty()) {
                List<SecurityQuestion> questions = Arrays.asList(
                    new SecurityQuestion(null, "你的小学名称是什么？", true),
                    new SecurityQuestion(null, "你的第一个宠物叫什么名字？", true),
                    new SecurityQuestion(null, "你最喜欢的颜色是什么？", true),
                    new SecurityQuestion(null, "你的出生地是哪里？", true),
                    new SecurityQuestion(null, "你最喜欢的食物是什么？", true),
                    new SecurityQuestion(null, "你最喜欢的电影是什么？", true),
                    new SecurityQuestion(null, "你最喜欢的运动是什么？", true),
                    new SecurityQuestion(null, "你的理想职业是什么？", true),
                    new SecurityQuestion(null, "你最喜欢的季节是什么？", true),
                    new SecurityQuestion(null, "你最喜欢的城市是哪里？", true)
                );
                for (SecurityQuestion question : questions) {
                    securityQuestionMapper.insert(question);
                }
                System.out.println("✅ 默认安全问题数据初始化完成，共插入 " + questions.size() + " 个问题");
            } else {
                System.out.println("✅ 安全问题数据已存在，跳过初始化");
            }
        };
    }
}
